package com.yuchen.ishop.web.app.interceptor;

import com.yuchen.ishop.service.buyer.BuyerRestClient;
import com.yuchen.ishop.vo.CookieUserInfo;
import com.yuchen.ishop.web.BaseAction;
import com.yuchen.jaxrs.Responses;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 会员拦截
 */
public class MyBuyerInterceptor implements HandlerInterceptor {

    private final static Logger LOG = Logger.getLogger(MySellerInterceptor.class);

    @Autowired
    private BuyerRestClient buyerRestClient;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LOG.debug(request.getServletPath());
        String url = request.getServletPath();
        CookieUserInfo userInfo = BaseAction.cookie2UserInfo(request);
        if (userInfo == null || !userInfo.isState()) {
            response.sendRedirect(request.getContextPath() + "/goLogin.htm");
            return false;
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }


}
